package com.oa.login.dao;

import com.oa.login.entity.Users;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;


@MapperScan
public interface UsersMapper {
    @Delete({
        "delete from users",
        "where id = #{id}"
    })
    int deleteByPrimaryKey(int id);

    @Insert({
        "insert into users (id, username, ",
        "password, password_salt)",
        "values (#{id}, #{username,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{passwordSalt,jdbcType=VARCHAR})"
    })
    int insert(Users record);

    int insertSelective(Users record);

    @Select({
        "select",
        "id, username, password, password_salt",
        "from users",
        "where id = #{id}"
    })
    @ResultMap("com.oa.login.dao.UsersMapper.BaseResultMap")
    Users selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Users record);

    @Update({
        "update users",
        "set username = #{username,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "password_salt = #{passwordSalt,jdbcType=VARCHAR}",
        "where id = #{id}"
    })
    int updateByPrimaryKey(Users record);
    
    
    @Select("select id from users where username=#{username}")
    int find(Users user);
    
    @ResultMap("com.oa.login.dao.UsersMapper.BaseResultMap")
    @Select("select * from users where username=#{username} and password = #{password}")
    Users findByUsers(Users user);
    
    @Select("select username from users where id = #{id}")
    String findById(int id);
}